<?php

namespace Home\Model;
use Think\Model;
class ClassModel extends BaseModel
{

    public function findFootLinks()
    {

        //底部链接                      'class_name like "%'.'服务中心'.'%"'
        $firstClass = $this->where('class_name like "%'.'服务中心'.'%"')->field('id')->find();
        //$firstList = M('class')->where('class_name = "服务中心" ')->field('id')->find();
        //$secondClass = $this->where('pid = '.$firstClass['id'])->field('id, class_name')->select();
       // $this->assign('secondClass',$secondClass);

        /*$Model = new \Think\Model(); // 实例化一个model对象 没有对应任何数据表
        $cla = $Model->query(
            "select a.class_name as thirdClass, b.secondClass from sd_class as a inner join (select id, class_name as secondClass from sd_class where pid = ". $firstClass['id'] ." order by sort desc) as b on a.pid = b.id"
        );*/
        $sql = "select a.class_name as thirdClass, b.secondClass from sd_class as a inner join (select id, class_name as secondClass from sd_class where pid = ". $firstClass['id'] ." order by sort desc) as b on a.pid = b.id";
        $cla = $this->sql_query($sql);
        if(!$cla)
        {
            return flase;
        }
        /*$j = 0;
        $claa = [];
        foreach ($cla as $k => $val)
        {
            if($j == 0)
            {
                $claa[$j]['secondclass'] = $val['secondclass'] ;
            }

            if(isset($cla[$k-1]['secondclass']) && $cla[$k]['secondclass'] != $cla[$k-1]['secondclass'])
            {
                $j++;
                $claa[$j]['secondclass'] = $val['secondclass'] ;
            }
            $claa[$j]['thirdclass'][] = $val['thirdclass'];
        }*/

        $claa = $this->parseSqlData($cla, 'secondclass', 'thirdclass');
        $claa['serList'] = $this->where('pid = 39')->field('class_name')->select();

        return $claa;

    }




}